package com.zee.example;


import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;

import com.zee.adapter.BaseMultiZAdapter;
import com.zee.base.ZActivity;
import com.zee.bean.MultiItemAdapter;
import com.zee.http.MyOk;
import com.zee.http.request.ZCacheStringResult;
import com.zee.recyclerview.LoadMoreListener;
import com.zee.recyclerview.RefreshListener;
import com.zee.base.BaseZAdapter;
import com.zee.log.ZLog;
import com.zee.view.ZxRecyclerView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


public class ZxOkMainActivity extends ZActivity {
    private ZxRecyclerView mXRecyclerView;
    private List<BeanTotal.DataBean> dataList = new ArrayList<>();
    private BaseZAdapter mBaseZAdapter;
    private BaseZAdapter mTestAdapter;
    private int curpage = 1;
    private RecyclerView mRecyclerView;

    @Override
    public int getLayoutResID() {
        return R.layout.activity_zx_ok_main;
    }

    @Override
    public void initViews(Bundle savedInstanceState) {
        mXRecyclerView = findViewById(R.id.id_recyclerView);
        mRecyclerView = findViewById(R.id.id_scroll_recyclerView);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayout.HORIZONTAL, false));
        BaseMultiZAdapter multiZAdapter;
        mRecyclerView.setAdapter(multiZAdapter = new BaseMultiZAdapter(null) {
            @Override
            public MultiItemAdapter getMultiItemAdapter(int viewType) {

                return new MultiItemAdapter() {
                    @Override
                    public int getLayoutResID() {
                        return R.layout.activity_zx_ok_test_item;
                    }

                    @Override
                    public void initViews(View parentView, int location) {

                    }
                };
            }
        });

//        mRecyclerView.setAdapter(mTestAdapter = new BaseZAdapter(dataList, R.layout.activity_zx_ok_test_item) {
//            @Override
//            protected void initViews(View parentView, int location) {
//                BeanTotal.DataBean bean = getBean();
//                TextView nameTextView = findViewById(R.id.id_name);
//                nameTextView.setText(bean.getNickName());
//            }
//        });
        mXRecyclerView.setLayoutManager(new LinearLayoutManager(this));
//        HintText hintText = mXRecyclerView.getHintText();
//        hintText.setTextColor(UIUtils.getColor(R.color.colorAccent));
//        hintText.setTextColor(Color.parseColor("#FFFFFF"));
//        hintText.setRefresh_hintReleaseHandText("拽的蛋疼a");
//        hintText.setLoadMore_noMoreText("别扯了,已经完蛋了");
//        hintText.setTextSize(UIUtils.spToPx(18));

//        mXRecyclerView.setRefreshView(new DRLoadingFreshViewRecyclerView());
//        mXRecyclerView.setLoadMoreView(new DRLoadingMoreViewRecyclerView());
//        mXRecyclerView.addHeaderView(getTextView(0));
//        mXRecyclerView.addHeaderView(getTextView(1));
//        mXRecyclerView.addHeaderView(getTextView(2));
//        mXRecyclerView.addHeaderView(getTextView(3));
//        mXRecyclerView.setAdapter(mBaseZAdapter = new BaseZAdapter(dataList, R.layout.activity_zx_ok_main_item) {
//            @Override
//            protected void initViews(View parentView, int location) {
//                BeanTotal.DataBean bean = getBean();
//                TextView nameTextView = findViewById(R.id.id_name);
//                nameTextView.setText(bean.getNickName());
//            }
//        });
//        mXRecyclerView.setRefreshAndLoadMordListener(new RefreshAndLoadMordListener() {
//            @Override
//            public void onLoadMore() {
//
//            }
//
//            @Override
//            public void onRefresh() {
//
//            }
//        });

        mXRecyclerView.setLoadMoreListener(new LoadMoreListener() {
            @Override
            public void onLoadMore() {
                ++curpage;
//                request();
                getRJData(0);
//                UIUtils.postDelayed(() -> mXRecyclerView.loadFinish(), 2000);
            }
        });
        mXRecyclerView.setRefreshListener(new RefreshListener() {
            @Override
            public void onRefresh() {
                curpage = 1;
//                request();
//                UIUtils.postDelayed(() -> mXRecyclerView.loadFinish(), 2000);
            }
        });
//        request();
        getRJData(0);

        //122916
    }


    public void getRJData(int paCurpage) {
        HashMap<String, Object> loStringObjectHashMap = new HashMap<>();
//        loStringObjectHashMap.put("catId", "other");
//        loStringObjectHashMap.put("menuId", "system_security");
//        loStringObjectHashMap.put("pageSize", "20");
//        loStringObjectHashMap.put("pageIndex", paCurpage);

        MyOk.load("http://image.so.com/j?q=北京&sn=0&pn=50").get().addInterceptor(new ThirdPartyInterceptor()).execute(new ZCacheStringResult() {
            @Override
            public void onSuccessAsyncThread(String data, boolean isFromCache) {
                ZLog.i(data);
            }

            @Override
            public void onError(boolean isCache, Exception e) {
                super.onError(isCache, e);
            }
        });

    }


}
